<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>compactWhitespace</title>
</head>

<body>
    <div id="filter-text"></div>
    <script>
        const compactWhitespace = str => str.replace(/\s{2,}/g, ' ');
        const filterText = document.getElementById('filter-text');
        filterText.textContent = compactWhitespace(`Lorem    Ipsum`);
    </script>
</body>

</html>